package cn.foodshopping.controller;

import cn.foodshopping.domain.Goods;
import cn.foodshopping.service.IGoodsService;
import cn.foodshopping.util.MyException;
import cn.foodshopping.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("goods")
public class GoodsController {
@Autowired
IGoodsService iGoodsService;


    @RequestMapping("queryGoodsByType")
    public Object queryGoodsByType(Integer typeid){

//        System.out.println("-----"+ map.get("typeid")+"---"+map);
        System.out.println("------"+typeid);
        HashMap<String,Object> map=new HashMap<>();
        List<Goods> goods=null;
        try {
            goods=iGoodsService.queryGoodsByType(typeid);
            map.put("code",200);
            map.put("msg","查询成功");
            map.put("data",goods);
        }catch (MyException e){
            map.put("code",201);
            map.put("msg",e.getMessage());
            map.put("data",null);
        }

        return map;

    }

    @RequestMapping ("queryGoodsById")
    public Object queryGoodsById(Integer id){

        System.out.println("------"+id);
        Goods goods=iGoodsService.queryGoodsById(id);
        System.out.println(goods.getBusinessId());
        Result result=iGoodsService.queryBusinessById(goods.getBusinessId(),goods);
        return result;
    }

}
